<!-- 详细公告 -->
<template>
  <div class="notice">
    <myheader title="公共栏详情栏" rightBtn="发布公告" @updataInfo="submit"></myheader>
    <!-- 公告 -->
    <div class="mynotice" v-if="!empty">
      <!-- 标题 -->
      <div class="title">{{notice.title}}</div>
      <!-- 作者+时间 -->
      <div>
        <li
          class="date"
          v-if="notice.user"
        >{{notice.user.username}} &nbsp;&nbsp; {{formatDateTime(notice.createTime)}}</li>
      </div>
      <!-- 内容 -->
      <div style="padding:15px;text-indent:2em;" class="content">{{notice.content}}</div>
    </div>

    <van-empty v-else image="error" description="暂无此内容！" />
  </div>
</template>

<script>
import myheader from '../../comon/myheader.vue'
import formatDateTime from '../../utils/data'
export default {
  components: {
    myheader,
  },
  data() {
    return {
      notice: [],
      noticeId: this.$route.params.id,
      empty: false,
    }
  },
  created() {
    this.init()
    console.log(this.notice)
  },
  methods: {
    formatDateTime(val) {
      return formatDateTime.formatDateTime4(val)
    },
    async init() {
      const res = await this.$axios.get('/notice/info/' + this.noticeId)
      if (res.data.code == 200) {
        this.notice = res.data.data

        if (res.data.data.total == 0) {
          this.empty = true
        } else {
          this.empty = false
        }
      }
    },
    submit() {
      this.$router.push('/addNotic')
    },
  },
}
</script>

<style scoped>
.notice {
  margin-top: 75px;
}
.title {
  font-size: 18px;
}
.date {
  font-size: 14px;
}
.content {
  font-size: 16px;
}

/* 公告内容 */
.mynotice {
  padding: 0 15px;
}
.mynotice > div {
  margin-top: 15px;
}
</style>
